package gspushmq.v1.produce.job;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.java_websocket.WebSocket;
import org.quartz.DisallowConcurrentExecution;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import gspushmq.model.ApiMessage;
import gspushmq.model.ApiMessageType;
import gspushmq.util.GGLogger;
import gspushmq.util.SynUtil;
import gspushmq.v1.produce.GGDataStorage;
import gspushmq.v1.produce.job.core.GGServiceJob;
import gspushmq.v1.subscribe.GGSubscribe;
import gspushmq.v1.subscribe.send.core.GGMessageSend;
import gspushmq.v1.websocket.core.GGPusherEnum;

/**
 * 
 * 心跳
 * 
 * @version 1.0
 * @since JDK1.7
 * @author lisl
 * @company 上海朝阳永续信息技术有限公司
 * @copyright (c) 2019 SunTime Co'Ltd Inc. All rights reserved.
 * @date 2019年1月16日 下午10:36:04
 */
@DisallowConcurrentExecution
public class HeartbeatJob extends GGServiceJob {

	@Override
	protected String setJobName(Map<String, Object> params) {
		return "服务端心跳";
	}
	
	@Override
	public void doServiceJob(Map<String, Object> args) {
		Enumeration<WebSocket> wsList = GGSubscribe.wstUser.keys();
		int i= 0;
		while (wsList.hasMoreElements()) {
			WebSocket ws = wsList.nextElement();
			ws.send("heartbeat...");
			i++;
		}
		GGLogger.debug(getClass(), "服务端心跳。。。  客户端数量：" + i + "/" + GGPusherEnum.pusher.getPusher().getConnections().size());
	}

}
